//=========================================================================
// Copyright (C) 2024 The C++ Component Model(COMO) Open Source Project
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//      http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//=========================================================================

// g++ -o custom_allocator testTlsfStdString.cpp ../tlsf/tlsf.c ../tlsf/TlsfStdString.cpp

/**
 * Important Considerations
 * 1. Thread Safety
 *     The default TLSF implementation is not thread-safe. If you're working in
 *     a multi-threaded environment, you may need to add locks or use separate
 *     TLSF pools per thread.
 * 2. Memory Pool Size
 *     The pool_size should be large enough to accommodate your application's
 *     memory needs.
 * 3. Error Handling
 *     Ensure you handle cases where memory allocation fails, as TLSF may throw
 *     std::bad_alloc if the pool is exhausted.
 * 4. Performance Testing
 *     Before deploying in an embedded or real-time environment, thoroughly test
 *     the allocator's performance and latency characteristics.
 */

#include <iostream>
#include "../tlsf/TlsfStdString.h"

using namespace como;

int main()
{
    printf("Minimum size of MemoryHolder: %ld\n", tlsf_size());

    MemoryHolder mh(50000);
    TlsfString str1("Hello, TLSF Allocator!", &mh);
    TlsfString str2 = str1 + " How are you?";

    std::cout << str1 << std::endl;
    std::cout << str2 << std::endl;

    return 0;
}
